package com.lql.mongodb;

import com.mongodb.MongoClient;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
import org.bson.Document;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by LQL on 2016/4/18.
 */
public class MongoDBUtil {


    public static void main(String[] args) {
        insertDocument();
    }

    public static void insertDocument() {
        MongoClient client = new MongoClient("10.103.240.194", 27017);

        //获取数据库
        MongoDatabase database = client.getDatabase("test");

        //获取集合
        MongoCollection<Document> collection = database.getCollection("User");


        Document document = new Document("userId", 126);
        document.append("profession", "学生");
        document.append("eduDegree", "硕士");
        document.append("grade", "2015级");


        List<Document> documents = new ArrayList<Document>();
        documents.add(document);
        collection.insertMany(documents);
    }
}
